home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / QuickDraw / Thumbnail Test / ShrinkToBW.c < prev    next >
Encoding:
Text File  |  1994-10-28  |  2.4 KB  |  89 lines  |  [TEXT/KAHL]

  1. // this file contains a routine to illustrate the use of copybits to generate thumbnail images
  2. //
  3.  
  4. #include <QDOffscreen.h>
  5. #include <PictUtil.h>
  6.  
  7. extern RGBColor kRGBBlack ;
  8. extern RGBColor kRGBWhite ;
  9. extern Point gStaggerPos ;
  10.  
  11.  
  12.  
  13. #define    SCALEFACTOR        15    // percent
  14.  
  15. void ShrinkToBWPict( WindowPtr theWindow )
  16. {
  17.     Rect        theBounds ;
  18.     GWorldPtr    theOldWorld, theNewWorld ;
  19.     OSErr        theErr ;
  20.     CGrafPtr    savedPort ;
  21.     GWorldPtr    savedGWorld ;
  22.     WindowPtr    newWindow ;
  23.     GDHandle    oldDevice ;
  24.     
  25.     PictInfo        thePictInfo ;
  26.     PaletteHandle    thePictPalette = nil ;
  27.     CTabHandle        thePictCTab = nil ;
  28.     
  29.     float        scaleFactor = SCALEFACTOR / 100.0 ;
  30.     
  31.     
  32.     // get the GWorld from the window refcon
  33.     theOldWorld = (GWorldPtr)GetWRefCon ( theWindow );
  34.     
  35.     // get the bounds of the window
  36.     theBounds = theOldWorld->portRect ;
  37.     
  38.     // apply the scaling factor
  39.     theBounds.top = scaleFactor * theBounds.top ;
  40.     theBounds.left = scaleFactor * theBounds.left ;
  41.     theBounds.bottom = scaleFactor * theBounds.bottom ;
  42.     theBounds.right = scaleFactor * theBounds.right ;
  43.     
  44.     // make a new one-bit gworld to hold the shrunken image
  45.     theErr = NewGWorld( &theNewWorld, 1, &theBounds, nil, nil, 0L ) ;
  46.     
  47.     if( theErr != noErr ) 
  48.         return ;
  49.     
  50.     // save the world
  51.     GetGWorld( &savedPort, &oldDevice ) ;
  52.     SetGWorld( theNewWorld, nil ) ;
  53.     
  54.     
  55.     RGBForeColor( &kRGBBlack ) ;        // ensure the fg and bg colors are 
  56.     RGBBackColor( &kRGBWhite ) ;        // as anticipated
  57.     EraseRect( &theBounds ) ;            // clear the area for the pict
  58.     PenMode( srcCopy ) ;                // ensure the t/f mode is as expected
  59.  
  60.  
  61.     // render the image into the offscreen buffer
  62.     CopyBits( &((GrafPtr)theOldWorld)->portBits,
  63.               &((GrafPtr)theNewWorld)->portBits,
  64.               &theOldWorld->portRect,
  65.               &theNewWorld->portRect,
  66.               patCopy | ditherCopy,
  67.               nil ) ;
  68.     
  69.     SetGWorld( savedPort, oldDevice ) ;
  70.     
  71.     // create the window
  72.     OffsetRect( &theBounds, gStaggerPos.h, gStaggerPos.v) ;
  73.     gStaggerPos.h += 16 ;
  74.     gStaggerPos.v += 16 ;        // heh - should roll these around, but you wont 
  75.                                 // create more than a couple of windows, will you  :-)
  76.                                  
  77.     newWindow  = NewCWindow( nil, &theBounds, "\pplayTime", true, 
  78.                                 documentProc, (WindowPtr)-1, true, (long)theNewWorld );    
  79.     
  80.     // make sure it is visible
  81.     ShowWindow( newWindow ) ;
  82.     
  83.     SetGWorld( (CGrafPtr)newWindow, nil ) ;
  84.     
  85.     // invalidate the content region of the window - we don't do any drawing to it here.
  86.     InvalRect ( &theBounds );
  87.     
  88.     SetGWorld( savedPort, oldDevice ) ;
  89. }